//
//  CNShopCarCell.m
//  BeeQuick_19
//
//  Created by w on 16/9/23.
//  Copyright © 2016年 CN Team. All rights reserved.
//

#import "CNShopCarCell.h"
#import "CNShopBuyView.h"
//导入字符串分类
#import "NSString+Extension.h"
@interface CNShopCarCell()
//标题lable
@property (nonatomic,strong) UILabel *titleLabel;
//价格label
@property (nonatomic,strong) UILabel *priceLabel;
//一个商品购买视图
@property (nonatomic,strong) CNShopBuyView *buyView;

@end
@implementation CNShopCarCell

//- (void)awakeFromNib {
//    [super awakeFromNib];
//    // Initialization code
//}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
    //重写cell的initWithStyle  进行cell内容重新布局
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
   //这里进行cell中内容的重新布局  首先进行判断调用父类的initWithStyle方法
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
#pragma mark 初始化标题titleLable 和priceLable GoodsView
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = [UIFont systemFontOfSize:12];
        [_titleLabel sizeToFit];
        _titleLabel.textColor = [UIColor blackColor];
        //将_titleLabel加入到容器视图中
        [self.contentView addSubview:_titleLabel];
        
        _priceLabel = [[UILabel alloc]init];
        _priceLabel.font = [UIFont systemFontOfSize:12];
        [_priceLabel sizeToFit];
        _priceLabel.textColor = [UIColor blackColor];
        //将_priceLabel加入到容器视图中
        [self.contentView addSubview:_priceLabel];
        
        _buyView = [[CNShopBuyView alloc]init];
        _buyView.tableView = self.tableView;
        [self.contentView addSubview:_buyView];
        
        //三个子控件的布局
        //_titleLabel _priceLabel CNShopBuyView
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView).offset(10);
            make.centerY.equalTo(self.contentView);
            make.width.offset(165);
        }];
        [_buyView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(70);
            make.height.mas_equalTo(50);
            make.centerY.equalTo(self.contentView);
            make.trailing.equalTo(self).offset(-20);
        }];
        [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_buyView.mas_right).offset(-150);
            make.centerY.equalTo(self.contentView);
        }];
    }
    return self;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    CNShopCarCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell_shop"];
    //设置选中cell的样式
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if(cell == nil){
        cell = [[CNShopCarCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell_shop"];
    }
    return cell;
}

//重写set方法来进行赋值
- (void)setGoods:(CNGoodsModel *)goods{
    self.titleLabel.text = [NSString stringWithFormat:@"[精选]%@",goods.name];
    self.priceLabel.text = [NSString stringWithFormat:@"单价[%.2f]",goods.partner_price];
    self.buyView.goods = goods;
}
@end
